package com.haiya.factory.method.pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public abstract class PizzaStore {
    public PizzaStore() {
        Pizza pizza = null;
        String orderType;
        do {
            orderType = getOrderType();
            /**
             * 抽象方法，由工厂子类完成
             */
            pizza = makePizza(orderType);
            /**
             * 输出pizza制作过程
             */
            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();
        } while (true);
    }


    /**
     * 定义一个抽象方法， makePizza, 让各个工厂子类自己实现
     * @param orderType
     * @return Pizza
     */
    public abstract Pizza makePizza(String orderType);

    private String getOrderType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type: ");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
